package cn.ibizlab.odoo.core.odoo_lunch.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ilunch_alert;
import cn.ibizlab.odoo.core.odoo_lunch.domain.Lunch_alert;
import cn.ibizlab.odoo.core.odoo_lunch.filter.Lunch_alertSearchContext;
import cn.ibizlab.odoo.core.odoo_lunch.service.ILunch_alertService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[午餐提醒] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Lunch_alertServiceImpl implements ILunch_alertService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ilunch_alertClientService lunch_alertClientService;

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ilunch_alert clientModel = lunch_alertClientService.createModel();
        clientModel.setId(id);
        lunch_alertClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean update(Lunch_alert lunch_alert) {
        boolean bOk = false ;
        Ilunch_alert clientModel = this.convert2Model(lunch_alert,null);
        lunch_alertClientService.update(clientModel) ;
        this.convert2Domain(clientModel,lunch_alert) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Lunch_alert> lunch_alerts, int batchSize) {

                        //lunch_alertClientService.createBatch(lunch_alerts,batchSize) ;

    }

    @Override
    public Lunch_alert get(Integer id) {
        Ilunch_alert clientModel = lunch_alertClientService.createModel();
        clientModel.setId(id);
        lunch_alertClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Lunch_alert get(Lunch_alert lunch_alert) {
        Lunch_alert retlunch_alert = this.get(lunch_alert.getId()) ;
    	BeanCopier copier=BeanCopier.create(retlunch_alert.getClass(), lunch_alert.getClass(), false);
        copier.copy(retlunch_alert, lunch_alert, null);
        return lunch_alert ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //lunch_alertClientService.removeBatch(lunch_alerts) ;

    }

    @Override
    public boolean create(Lunch_alert lunch_alert) {
        boolean bOk = false ;
        Ilunch_alert clientModel = this.convert2Model(lunch_alert,null);
        lunch_alertClientService.create(clientModel) ;
        this.convert2Domain(clientModel,lunch_alert);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void updateBatch(List<Lunch_alert> lunch_alerts, int batchSize) {

        //lunch_alertClientService.updateBatch(lunch_alerts,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Lunch_alert> searchDefault(Lunch_alertSearchContext context) {
        List<Lunch_alert> list = new ArrayList<Lunch_alert>();
        Page<cn.ibizlab.odoo.core.client.model.Ilunch_alert> clientModelList = lunch_alertClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ilunch_alert clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Lunch_alert>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据联系人查询
     */
    @Override
    public Page<Lunch_alert> selectByOdoo_partner(Integer id){
        Lunch_alertSearchContext context = new Lunch_alertSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Lunch_alert> list = new ArrayList<Lunch_alert>();
        Page<cn.ibizlab.odoo.core.client.model.Ilunch_alert> clientModelList = lunch_alertClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ilunch_alert clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Lunch_alert>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Lunch_alert> selectByOdoo_create(Integer id){
        Lunch_alertSearchContext context = new Lunch_alertSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Lunch_alert> list = new ArrayList<Lunch_alert>();
        Page<cn.ibizlab.odoo.core.client.model.Ilunch_alert> clientModelList = lunch_alertClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ilunch_alert clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Lunch_alert>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Lunch_alert> selectByOdoo_write(Integer id){
        Lunch_alertSearchContext context = new Lunch_alertSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Lunch_alert> list = new ArrayList<Lunch_alert>();
        Page<cn.ibizlab.odoo.core.client.model.Ilunch_alert> clientModelList = lunch_alertClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ilunch_alert clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Lunch_alert>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ilunch_alert convert2Model(Lunch_alert domain , Ilunch_alert model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = lunch_alertClientService.createModel() ;
        }

         if(domain.getSpecific_dayDirtyFlag())
            model.setSpecific_day(domain.getSpecific_day());
         if(domain.getDisplayDirtyFlag())
            model.setDisplay(domain.getDisplay());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getThursdayDirtyFlag())
            model.setThursday(domain.getThursday());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getWednesdayDirtyFlag())
            model.setWednesday(domain.getWednesday());
         if(domain.getTuesdayDirtyFlag())
            model.setTuesday(domain.getTuesday());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getMessageDirtyFlag())
            model.setMessage(domain.getMessage());
         if(domain.getAlert_typeDirtyFlag())
            model.setAlert_type(domain.getAlert_type());
         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.getSaturdayDirtyFlag())
            model.setSaturday(domain.getSaturday());
         if(domain.getStart_hourDirtyFlag())
            model.setStart_hour(domain.getStart_hour());
         if(domain.getMondayDirtyFlag())
            model.setMonday(domain.getMonday());
         if(domain.getFridayDirtyFlag())
            model.setFriday(domain.getFriday());
         if(domain.getEnd_hourDirtyFlag())
            model.setEnd_hour(domain.getEnd_hour());
         if(domain.getSundayDirtyFlag())
            model.setSunday(domain.getSunday());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Lunch_alert convert2Domain( Ilunch_alert model ,Lunch_alert domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Lunch_alert();
        }

        if(model.getSpecific_dayDirtyFlag())
            domain.setSpecific_day(model.getSpecific_day());
        if(model.getDisplayDirtyFlag())
            domain.setDisplay(model.getDisplay());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getThursdayDirtyFlag())
            domain.setThursday(model.getThursday());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getWednesdayDirtyFlag())
            domain.setWednesday(model.getWednesday());
        if(model.getTuesdayDirtyFlag())
            domain.setTuesday(model.getTuesday());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getMessageDirtyFlag())
            domain.setMessage(model.getMessage());
        if(model.getAlert_typeDirtyFlag())
            domain.setAlert_type(model.getAlert_type());
        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.getSaturdayDirtyFlag())
            domain.setSaturday(model.getSaturday());
        if(model.getStart_hourDirtyFlag())
            domain.setStart_hour(model.getStart_hour());
        if(model.getMondayDirtyFlag())
            domain.setMonday(model.getMonday());
        if(model.getFridayDirtyFlag())
            domain.setFriday(model.getFriday());
        if(model.getEnd_hourDirtyFlag())
            domain.setEnd_hour(model.getEnd_hour());
        if(model.getSundayDirtyFlag())
            domain.setSunday(model.getSunday());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
